package com.example.common.vp;

import android.content.Context;

import androidx.databinding.ViewDataBinding;

import com.example.common.base.AbsActivity;
import com.example.common.vp.interfaces.IPresenter;
import com.example.common.vp.interfaces.IView;

public abstract class BaseActivity<B extends ViewDataBinding, P extends IPresenter> extends AbsActivity<B> implements IView{

    protected P mPresenter;
    protected boolean regEvent;

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void main() {
        mPresenter=getPresenter();
        if (mPresenter != null) {
            mPresenter.attachView(this);
            getLifecycle().addObserver(mPresenter);
        }
    }

    protected abstract P getPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }

    }
}
